from rest_framework import serializers
from .models import SKU,SPU


class SKUSer(serializers.ModelSerializer):

    cate_name = serializers.SerializerMethodField(read_only=True)

    def get_cate_name(self,obj):
        return obj.cate.name

    class Meta:
        model = SKU
        fields = "__all__"


class SpuSer(serializers.ModelSerializer):
    brand_name = serializers.SerializerMethodField(read_only=True)

    def get_brand_name(self, obj):
        return obj.brand.name

    category2 = serializers.SerializerMethodField(read_only=True)

    def get_category2(self, obj):
        return obj.category2.name

    category3 = serializers.SerializerMethodField(read_only=True)

    def get_category3(self, obj):
        return obj.category3.name


    class Meta:
        model = SPU
        fields = "__all__"